<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of PublicActionclass
 *
 * @author Administrator
 */
class PublicAction extends BaseAction{

    public function reging(){
        $Dao = D('User');
        //判断者个用户名是否注册
        $count = $Dao->find("loginname='".$_POST['loginname']."'");

        if($count){
            $this->error("您输入的用户名已经被注册了，请更换一个。");
        }

        $Dao->create();
        $isSuccess = $Dao->add();
        if($isSuccess){
            $this->assign("jumpUrl",__APP__.'/index/index');
            $this->success("恭喜您，注册成功");
        }else{
            $this->error("注册 失败。");
        }

    }

    public function checklogin(){
        $loginname		=	isset($_POST["loginname"]) ? $_POST["loginname"] : Cookie::get("loginname");
        $password	=	isset($_POST["password"]) ? $_POST["password"] : Cookie::get("password");
        if(md5($_POST['verify']) != $_SESSION['verify']){
            $this->error("验证码输入错误!");
        }
        //验证用户信息

        $userDao	=	D('User');
        $user		=	$userDao->where("loginname='".$loginname."' and password='".$password."'")->find();
        //dump($userDao->getLastSql());
        //验证成功
        if($user){
            Session::set('mid',$user['id']);

            Session::set('userInfo',$user);
            Cookie::set('password',$password,36000000);
            unset($loginname,$password);
            $this->assign("jumpUrl",__APP__.'/index/index');
            $this->success('登录成功！');
        }else{
            //跳转到登陆页面
            $this->assign("jumpUrl",__APP__.'/index/index');
            $this->error('验证失败,请重新登入!');
        }

    }

    public function logout(){
        Session::clear();

        Cookie::clear();
        //$this->redirect("index","Index");

        $this->assign('jumpUrl',__APP__.'/index/index');
        $this->success('注销成功!');

    }

    public function verify(){
        import("ORG.Util.Image");
        Image::buildImageVerify();
    }

}
?>
